<?php

require_once 'common/conn.php';
if (isset($_GET['age'])) {
    $age = $_GET['age'];
}
if (isset($_GET['type'])) {
    $type = $_GET['type'];
}
if (isset($_GET['ability'])) {
    $ability = $_GET['ability'];
}
$data = array();
if (isset($age) && isset($type) && isset($ability)) {
    $db = new DBC();
    if (isset($_GET['flashcode'])) {
        $db = new DBC();
        $flashcode = $_GET['flashcode'];
        $products = json_decode($flashcode, true);
        $codes = "";
        foreach ($products as $pro) {
            $codes = $codes . "," . $pro['flashcode'];
        }
        if (strlen($codes) > 0) {
            if (substr($codes, 0, 1) == ',') {
                $codes = substr($codes, 1, strlen($codes));
            }
        }
        $sql = "SELECT productid,flashcode,age,name,url_en AS url,imageURL,version,size,type1,type2,downloadtimes FROM t_product WHERE status_en = 1 AND flashcode NOT IN ('" . $codes . "') AND age = " . $age . " AND type1 = '" . $type . "' AND type2 LIKE '%" . $ability . "%' ORDER BY flashcode";
    } else {
        $sql = "SELECT productid,flashcode,age,name,url_en AS url,imageURL,version,size,type1,type2,downloadtimes FROM t_product WHERE status_en = 1 AND age = " . $age . " AND type1 = '" . $type . "' AND type2 LIKE '%" . $ability . "%' ORDER BY flashcode";
    }
    $data = $db->fetchData($sql);
}
echo json_encode($data);
?>